package com.thirteen.app.controller;

import com.thirteen.app.dto.AnswerQuestionDto;
import com.thirteen.app.entity.Answer;
import com.thirteen.app.entity.Question;
import com.thirteen.app.service.QuestionService;
import com.thirteen.app.utils.tools.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.oas.annotations.EnableOpenApi;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 题目(Question)表控制层
 *
 * @author 郑清林
 * @since 2021-09-06 10:29:43
 */

@CrossOrigin
@Api(tags = "题目管理模块")
@EnableOpenApi
@RestController
@RequestMapping("/api/student/question")
public class QuestionController {

    @Resource
    private QuestionService questionService;


    @ApiOperation("删除题目")
    @PostMapping("deleteQu")
    public CommonResult deleteQuestion(Integer questionId, Integer repositoryId) {
        return CommonResult.success(questionService.deleteQuestion(questionId, repositoryId));
    }

    @ApiOperation("插入一条题目信息,并且插入对应的答案列表")
    @PostMapping("createQu")
    public CommonResult insert(@RequestBody Question question, @RequestBody List<AnswerQuestionDto> answers) {
        return CommonResult.success(questionService.insert(question, answers));
    }

    @ApiOperation("根据题目查询答案")
    @GetMapping("selectQu")
    public CommonResult getquestionPageList(Integer currentPage,
                                            Integer pageSize,
                                            Integer questionType,
                                            Integer repositoryId,
                                            Integer id) {
        Map<String, Object> map = questionService.getquestionPageList(1, 10, questionType, repositoryId, id);
        return CommonResult.success(map);
    }

    @PostMapping("getQuestionList")
    @ApiOperation("获取题目列表")
    public CommonResult getQuestionList(Integer id, Integer mode, Integer[] types, Integer userId) {
        return CommonResult.success(questionService.getQuestionList(id, mode, types, userId));
    }

}
